package org.jeecg.talentCooperation.talent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.talentCooperation.common.vo.Result;
import org.jeecg.talentCooperation.talent.entity.TalentBasic;
import org.jeecg.talentCooperation.talent.model.TalentFruitResultModel;
import org.jeecg.talentCooperation.talent.model.TalentResultModel;
import org.jeecg.talentCooperation.talent.service.ITalentBasicService;
import org.jeecg.talentCooperation.talent.service.ITalentFieldRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @Description: 人才协作
 * @Author: jeecg-boot
 * @Date:   2023-8-17
 * @Version: V1.0
 */
@RestController
@RequestMapping("/ndTalent/talents")
@Slf4j
public class TalentController {
	@Autowired
	private ITalentBasicService basicService;
	@Autowired
	private ITalentFieldRelService talentFieldRelService;

	@PostMapping(value = "/getTalentInfo")
	public Result<?> getTalentInfo(@RequestBody TalentBasic talentBasic) {
		return Result.OK(talentFieldRelService.getByTalentId(talentBasic.getId()));
	}


	/**
	 * 个人研究趋势
	 *
	 * @param talentBasic
	 * @return
	 */
	@PostMapping(value = "/getTalentResearchTrends")
	public Result<?> getTalentResearchTrends(@RequestBody TalentBasic talentBasic) {

		List<TalentResultModel> talentResultModelList = basicService.getTalentResearchTrends(talentBasic);
//		Map<String, Integer> map = new HashMap();
//		talentResultModelList.forEach(
//			talentResultModel -> {
//				String tName = talentResultModel.getName();
//				String tYear = talentResultModel.getYearNum();
//				int tCount = talentResultModel.getCount();
//				String mapKey = tName + "," + tYear;
//			  	if (tName.contains(";")) {
//					String[] talentResNameArr = talentResultModel.getName().split(";");
//					for (String s : talentResNameArr) {
//						mapKey = s + ","  + tYear;
//						map.merge(mapKey, tCount, Integer::sum);
//					}
//			  	}else{
//				  	map.merge(mapKey, tCount, Integer::sum);
//			  	}
//			});
//
//		List<TalentResultModel> resultList = new ArrayList<>();
//		map.forEach((key, value) -> {
//			TalentResultModel talentResultModel = new TalentResultModel();
//			talentResultModel.setName(key.split(",")[0]);
//			talentResultModel.setYearNum(key.split(",")[1]);
//			talentResultModel.setCount(value);
//			resultList.add(talentResultModel);
//		});

		return Result.OK(talentResultModelList);
	}

	/**
	 * 专家数据
	 *
	 * @param talentFruitResultModel
	 * @return
	 */
	@PostMapping(value = "/getTalentInfoData")
	public Result<?> getTalentInfoData(@RequestBody TalentFruitResultModel talentFruitResultModel) {

		Integer pageNo = talentFruitResultModel.getPageNo();
		Integer pageSize = talentFruitResultModel.getPageSize();

		talentFruitResultModel.setPageNo((pageNo - 1) * pageSize);
		talentFruitResultModel.setPageSize(pageSize);
		Page<TalentFruitResultModel> talentFruitPageList = new Page<TalentFruitResultModel>(pageNo, pageSize);
		talentFruitPageList = basicService.getTalentInfoData(talentFruitPageList, talentFruitResultModel);

		return Result.OK(talentFruitPageList);
	}


	/**
	 * 合作次数排行
	 *
	 * @param talentFruitResultModel
	 * @return
	 */
	@PostMapping(value = "/getTalentInfoDataOfCooNum")
	public Result<?> getTalentInfoDataOfCooNum(@RequestBody TalentFruitResultModel talentFruitResultModel) {

		List<TalentFruitResultModel> talentFruitPageList = basicService.getTalentInfoDataOfCooNum( talentFruitResultModel);

		return Result.OK(talentFruitPageList);
	}


	/**
	 * 成果数量排行
	 *
	 * @param talentFruitResultModel
	 * @return
	 */
	@PostMapping(value = "/getTalentInfoDataOfFruitNum")
	public Result<?> getTalentInfoDataOfFruitNum(@RequestBody TalentFruitResultModel talentFruitResultModel) {

		List<TalentFruitResultModel> talentFruitPageList = basicService.getTalentInfoDataOfFruitNum(talentFruitResultModel);

		return Result.OK(talentFruitPageList);
	}

}
